<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/layui/layui.js"></script>
    <link rel="stylesheet" href="../js/layui/css/layui.css"/>
</head>
<body>
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm"  onclick="openAddDialog()">新增</button>
    </div>
    <table class="layui-hide" id="companyMesssageTable" lay-filter="companyMessageFilter"></table>
</body>
<script>
    var table;
    var $;
    layui.use(['table'], function() {
        table = layui.table;
        $ = layui.jquery;
        $(function() {
            table.render({
                id: 'companyMesssageTableId',
                elem: '#companyMesssageTable',
                fit: true,
                url: '../company/findConypanyMessage', //数据接口
                cols: [
                    [ //表头
                        {type: 'checkbox', fixed: 'left'},
                        {field: 'touch', title: '联系人', align: 'center'},
                        {field: 'tel', title: '联系人电话', align: 'center'},
                        {field: 'email', title: '联系邮箱', align: 'center'},
                        {field: 'touchQq', title: '联系QQ', align: 'center'},
                        {field: 'comxingzhi', title: '公司性质', align: 'center',templet:function(data){
                            return data.comxingzhi == 1 ? "国企" : "私企";
                        }},
                        {field: 'address', title: '公司地址', align: 'center'},
                        {field: 'hangye', title: '行业', align: 'center'},
                        {field: 'comguimo', title: '公司规模', align: 'center',templet:function(data){
                            if(data.comguimo ==1){
                                return "100人以内"
                            }if(data.comguimo ==2){
                                return "100-200人"
                            }if(data.comguimo ==3){
                                return "200人以上"
                            }
                        }},
                        {field: 'comInfo', title: '企业简介', align: 'center'},
                        {field: 'licheng', title: '公司历程', align: 'center'},
                        {fixed: 'right', title: '操作', align: 'center', toolbar: '#toolbar'}
                    ]
                ]
            })
        })
        table.on('tool(companyMessageFilter)', function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                openEditMessageDialog(data.comId);
            }
        })
    })

    //打开新增弹框
    function openAddDialog(){
        layer.open({
            type: 2,
            title:"新增公司信息",
            area: ['700px', '500px'],
            fixed:false,
            maxmin:true,
            content:'../page/toAddCompanyMessage',
            btn:['保存'],
            btn1: function(index,layero){
                //获取子页面
                var iframeWin= window[layero.find('iframe')[0]['name']];//得到iframe页的窗口对象,执行iframe页的方法
                iframeWin.saveCompanyAccountMessage();
                table.reload("accountTableId",{});
                layer.close(index);
            },
        });
    }

    //打开修改弹框
    function openEditMessageDialog(id){
        layer.open({
            type:2,
            title:'编辑资料',
            area: ['800px', '500px'],
            fixed: false, //不固定
            maxmin: true,
            content: '../page/toEditCompanyMessage',
            btn:['保存'],
            success: function(layero,index){
                $.ajax({
                    url:'../company/findCompanyMessageById',
                    data:{id:id},
                    dataType:'json',
                    type:'post',
                    success:function (data) {
                        var iframeWin=window[layero.find("iframe")[0]["name"]];
                        iframeWin.editForm(data);
                    }
                })
            },
            btn1:function (index,layero) {
                var iframeWin=window[layero.find("iframe")[0]["name"]];
                iframeWin.saveCompanyAccountMessage();
                layer.close(index);
                table.reload("companyMesssageTableId",{})
            }
        })
    }

</script>
<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-xs" lay-event="edit">查看详情</a>
</script>
</html>